﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.EntityFrameworkCore.Storage;

namespace Jack.EntityFrameworkCore
{
    public interface IUnitOfWork : IDisposable, IAsyncDisposable, IDbConnection
    {
        Task<int> SaveChanges(CancellationToken cancellationToken = default);
        //Task Rollback(CancellationToken cancellationToken = default);
        //Task Complete(CancellationToken cancellationToken = default);
        Task<IDbContextTransaction> BeginTransaction(CancellationToken cancellationToken = default);
        void OpenTransactionScope();
        void SetTransactionScopeFailed();
        Task TransactionDecorator(Func<IDbTransaction, Task> func);
        void TransactionDecorator(Action<IDbTransaction> action);
        void TryOpen();
        IRepository<TModel> CreateRepository<TModel>() where TModel : class, IBaseModel, new();
    }

    public interface IEfCoreUnitOfWork<TDbContext> : IUnitOfWork, IDisposable, IAsyncDisposable, IDbConnection
        where TDbContext : JackDbContext<TDbContext>
    {
        TDbContext DbContext { get; }

        IEfCoreRepository<TModel> CreateEfCoreRepository<TModel>() where TModel : class, IBaseModel, new();
    }
}
